#include "mainwindow.h"

#include <QtWidgets/QVBoxLayout>
#include <QtWidgets/QHBoxLayout>
#include <QtWidgets/QLabel>
#include <QtWidgets/QPushButton>
#include <QtWidgets/QMessageBox>

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , m_centralWidget(nullptr)
    , m_mainLayout(nullptr)
    , m_titleLabel(nullptr)
    , m_button(nullptr)
{
    setupUI();
}

MainWindow::~MainWindow()
{
}

void MainWindow::setupUI()
{
    // Set window title
    setWindowTitle(tr("UOS Qt Application"));
    
    // Create central widget
    m_centralWidget = new QWidget(this);
    setCentralWidget(m_centralWidget);
    
    // Create main layout
    m_mainLayout = new QVBoxLayout(m_centralWidget);
    m_mainLayout->setContentsMargins(20, 20, 20, 20);
    m_mainLayout->setSpacing(10);
    
    // Create title label
    m_titleLabel = new QLabel(tr("Welcome to UOS Qt Application"), m_centralWidget);
    QFont titleFont = m_titleLabel->font();
    titleFont.setPointSize(16);
    titleFont.setBold(true);
    m_titleLabel->setFont(titleFont);
    m_titleLabel->setAlignment(Qt::AlignCenter);
    m_mainLayout->addWidget(m_titleLabel);
    
    // Add spacer
    m_mainLayout->addSpacing(20);
    
    // Create description label
    QLabel *descLabel = new QLabel(tr("This is a sample Qt application for UOS on loongarch architecture."), m_centralWidget);
    descLabel->setWordWrap(true);
    descLabel->setAlignment(Qt::AlignCenter);
    m_mainLayout->addWidget(descLabel);
    
    // Add spacer
    m_mainLayout->addSpacing(30);
    
    // Create button
    m_button = new QPushButton(tr("Click Me"), m_centralWidget);
    m_button->setMinimumHeight(40);
    m_mainLayout->addWidget(m_button, 0, Qt::AlignCenter);
    
    // Add stretch to push everything to the top
    m_mainLayout->addStretch(1);
    
    // Connect button signal to slot
    connect(m_button, &QPushButton::clicked, this, &MainWindow::onButtonClicked);
    
    // Set minimum size for the window
    setMinimumSize(400, 300);
}

void MainWindow::onButtonClicked()
{
    QMessageBox::information(this, tr("Button Clicked"), 
                            tr("Hello! This is a Qt application running on UOS for loongarch architecture."));
}